package com.cysion.study.ui.login

import com.cysion.other.color
import com.cysion.study.R
import com.cysion.study.helper.UserCache
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.study.net.ApiClient
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.widget.ShowToast
import com.cysion.targetfun._subscribe
import kotlinx.android.synthetic.main.activity_webview.*

class WebViewActivity : BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_webview
    }

    var type = ""
    override fun initView() {
        darkTextTheme(color(R.color.white))
        type = intent.extras.getString("type")
        //类型：1、家长端关于介绍；2、教师端关于介绍 3.家长端用户协议 4.家长端隐私政策 5.普教端用户协议 6.普教端隐私政策
        topbar.apply {
            setTitleBackColor(color(R.color.white))
            if (type == "1" || type == "2") {
                setTitle("关于我们")
            } else if (type == "3"||type=="5") {
                setTitle("用户协议")
            } else if (type == "4"||type=="6") {
                setTitle("隐私政策")
            }
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }
            }
        }
        getDataList()
    }

    private fun getDataList() {
        Alert.loading(this)
        //type：1、家长端关于介绍；2、教师端关于介绍 3.家长端用户协议 4.家长端隐私政策 5.普教端用户协议 6.普教端隐私政策
        ApiClient.api.getAboutInfo(type, UserCache.token).compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()

                    var content = it.content
                    wb_content.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null)

                }
                _onError {
                    Alert.close()

                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }


    override fun closeMvp() {
    }

}
